package com.rongchuang.controller;

import com.rongchuang.dto.MenuDTO;
import com.rongchuang.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 分页查询菜单信息
     */
    @GetMapping("page")
    public Page<MenuDTO> pageSearch(@RequestParam(defaultValue = "0") int pageNum,
                                    @RequestParam(defaultValue = "10") int pageSize,
                                    String name) {
        return menuService.pageSearch(pageNum, pageSize, name);
    }

    /**
     * 保存菜单信息
     */
    @PostMapping("modify")
    public void modify(@RequestBody MenuDTO menuDTO) {
        menuService.modify(menuDTO);
    }

    /**
     * 获取菜单信息
     */
    @GetMapping("detail/{id}")
    public MenuDTO detail(@PathVariable Long id) {
        return menuService.getDetail(id);
    }
}
